<template>
  <div class="container">
    <div class="top">
      <el-date-picker
        value-format="yyyy-MM-dd"
        v-model="date"
        type="daterange"
        :clearable="false"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
      <el-select v-model="search.os" placeholder="请选择类型">
        <el-option
          v-for="item in osList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-button type="info" icon="el-icon-tickets" @click="derive()"
        >导出</el-button
      >
      <el-button
        type="primary"
        class="handleSearch"
        icon="el-icon-search"
        @click="handleSearch()"
        >查询</el-button
      >
      <el-button
        type="danger"
        class="handleSearch"
        icon="el-icon-delete"
        @click="empty()"
        >清空</el-button
      >
    </div>
    <el-table
      max-height="600"
      :data="tableData"
      border
      style="width: 100%"
      empty-text="暂无数据"
    >
      <el-table-column
        prop="supplier_code"
        label="供应商编码"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="xsfmc"
        label="供应商名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="fpdm"
        label="发票代码"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="fphm"
        label="发票号码"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="file_name"
        label="发票文件名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="xmmc"
        label="商品名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="add_time"
        label="记录时间"
        align="center"
      ></el-table-column>
      <!-- <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope"> </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <pagination
      @page="handleSizeChange"
      @pagesize="handleCurrentChange"
      :pageData="pageData"
    ></pagination>
  </div>
</template>
<script>
import Pagination from "@/components/pagination";
import { getToken } from "@/utils/auth";
import { matchFailList } from "@/api/bill";
export default {
  components: {
    pagination: Pagination
  },
  data() {
    return {
      //页面数据
      tableData: [],
      //分页
      pageData: {
        pageSizes: [10, 20],
        pageSize: 10,
        page: 1,
        total: null,
        layout: "total, sizes, prev, pager, next, jumper"
      },
      search: {
        start_date: "",
        end_date: "",
        os: 1
      },

      osList: [
        {
          value: 1,
          label: "生鲜"
        },
        {
          value: 2,
          label: "商超"
        }
      ],
      date: []
    };
  },

  created() {
    //页面数据
    this.getData();
  },
  methods: {
    //页面数据
    getData() {
      let data = {
        limit: this.pageData.pageSize,
        page: this.pageData.page,
        start_date: this.search.start_date,
        end_date: this.search.end_date,
        os: this.search.os
      };
      matchFailList(data)
        .then(res => {
          if (res.code == 0) {
            this.tableData = res.data.paginate.data;
            this.pageData.page = res.data.paginate.current_page;
            this.pageData.pagesize = res.data.paginate.per_page;
            this.pageData.total = res.data.paginate.total;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 导出
    derive() {
      this.$confirm("是否导出?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          if (this.date.length > 0) {
            this.search.start_date = this.date[0];
            this.search.end_date = this.date[1];
          }
          let link = document.createElement("a");
          link.href =
            this.$axios.defaults.baseURL +
            "/api/Invoicexd/exportMatchFailList?token=" +
            getToken() +
            "&start_date=" +
            this.search.start_date +
            "&end_date=" +
            this.search.end_date +
            "&os=" +
            this.search.os;
          link.click();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消导出"
          });
        });
    },
    // 本地搜索
    handleSearch() {
      if (this.date.length > 0) {
        this.search.start_date = this.date[0];
        this.search.end_date = this.date[1];
      }
      this.pageData.page = 1;
      this.pageData.total = null;
      this.getData();
    },
    //添加

    //清空
    empty() {
      this.date = [];
      this.search = {
        start_date: "",
        end_date: "",
        os: 1
      };
    },

    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;
      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;
      this.getData();
    }
  }
};
</script>
<style scoped>
.top {
  position: relative;
  margin-bottom: 5px;
}
.btnList {
  position: relative;
  margin-bottom: 5px;
}
.add {
  position: absolute;
  right: 0;
  top: 4px;
}
.pagination {
  text-align: right;
  padding: 10px;
}
</style>
